home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj8412.arc / BIN_F.ASM < prev    next >
Assembly Source File  |  1986-01-18  |  5KB  |  104 lines

  1. BIN_F    PROC     NEAR
  2. ;*************************************************************
  3. ;                  converts an ASCII decimal number to 
  4. ;                  binary floating point
  5. ;                  Input--DI points to points to end of ASCII
  6. ;                         string; SI points to start
  7. ;*************************************************************
  8.          PUSH     SI
  9.          PUSH     DI
  10. ;                            convert ASCII mantissa to integer
  11.          CALL     BIN32           ;integer in DX:AX
  12.          OR       BX,BX           ;did it convert OK?
  13.          JZ       BINF1           ;if error
  14.          JMP      BINF9           ;jump
  15. ;                            check for zero result
  16. BINF1:   MOV      BX,DX
  17.          OR       BX,AX
  18.          JNZ      BINF2           ;finished if zero
  19.          JMP      BINF8 
  20. ;                            get sign
  21. BINF2:   PUSH     CX              ;save count of decimal places
  22.          SUB      CX,CX           ;assume positive sign
  23.          OR       DX,DX
  24.          JNS      BINF3
  25.          DEC      CX              ;negative sign
  26.          NOT      AX              ;make it positive
  27.          NOT      DX
  28.          ADD      AX,1
  29.          ADC      DX,0
  30. ;                            convert 32-bit integer to f.p
  31. BINF3:   MOV      BX,152          ;initial exponent=24+bias
  32.          OR       DH,DH           ;if DH
  33.          JZ       BINF4           ;is not zero
  34.          XCHG     AH,AL           ;shift right 8 bits
  35.          XCHG     DL,AH
  36.          XCHG     DH,DL           ;integer now in DL:AX:DH
  37.          ADD      BX,8            ;increment exponent
  38. ;                            normalize
  39. BINF4:   OR       DL,DL
  40.          JS       BINF5           ;if no sign bit
  41.          SHL      DH,1            ;shift integer left
  42.          RCL      AX,1
  43.          RCL      DL,1
  44.          DEC      BX              ;and decrement exponent
  45.          JMP      BINF4
  46. BINF5:   MOV      DH,BL           ;exponent in DH
  47. ;                            ;restore sign
  48.          OR       CX,CX
  49.          JNZ      BINF6
  50.          AND      DL,07FH         ;make sign positive
  51. BINF6:   PUSH     AX              ;save result--ASCII mantissa
  52.          PUSH     DX
  53. ;                            check for exponent
  54.          SUB      AX,AX           ;zero exponent
  55.          MOV      DX,AX
  56.          CMP      SI,DI           ;if at end of ASCII string
  57.          JAE      BINF7           ;no ASCII exponent
  58.          MOV      BL,[SI]         ;next unconverted char in BL
  59.          OR       BL,32           ;convert to lower case
  60.          CMP      BL,"e"          ;if not an "E"
  61.          JNE      BINF7           ;there is no exponent
  62. ;                            convert exponent
  63.          INC      SI              ;point to next char
  64.          CALL     BIN32           ;convert exponent to binary
  65.          OR       BX,BX           ;check for error
  66.          JNZ      BINF9  
  67. ;                            check exponent range
  68.          OR       DX,DX           ;DX should be zero if exponent
  69.          JZ       BINF7           ;positive and less than 2^16
  70.          CMP      DX,-1           ;or -1 if negative
  71.          JNE      BINF9           ;jump if out of range
  72. ;                            apply exponent to mantissa
  73. BINF7:   MOV      BX,AX           ;signed exponent in BX
  74.          POP      DX              ;retrieve mantissa in DX:AX
  75.          POP      AX
  76.          POP      CX              ;count of decimal places
  77.          ADD      BX,CX           ;subtract decimal places
  78.          JZ       BINF8           ;finished if exponent is zero
  79. ;                            compute exponent power of 10
  80.          PUSH     AX              ;save mantissa while we 
  81.          PUSH     DX              ;compute exponent
  82.          MOV      IM2,BX          ;integer exponent in IM2
  83.          MOV      SI,OFFSET IM2   ;address in SI
  84.          MOV      IM1,0           ;floating point 10
  85.          MOV      IM1+2,8420H     ;in IM1
  86.          MOV      DI,OFFSET IM1   ;address in DI
  87.          CALL     IPOWER_F        ;compute exponent
  88.          POP      [DI]+2          ;retrieve mantissa and 
  89.          POP      [DI]            ;put it in IM1
  90.          OR       BX,BX           ;check for errors
  91.          JNZ      BINF9  
  92.  
  93.          MOV      IM2,AX          ;put exponent in IM2
  94.          MOV      IM2+2,DX
  95. ;                            multiply mantissa x exponent
  96.          CALL     MUL_F
  97.          OR       BX,BX           ;check for errors
  98.          JNZ      BINF9 
  99. ;                            exit with result in DX:AX
  100. BINF8:   SUB      BX,BX           ;BX=0--status OK
  101.          JMP      EXIT
  102. BINF9:   MOV      BX,1            ;exit with error
  103.          JMP      EXIT
  104. BIN_F    ENDP